﻿using System;

namespace Validate.Net
{
    /// <summary>
    /// 校验字符串长度区间
    /// </summary>
    public class ValidateRangeLengthAttribute : AbstractValidateAttribute
    {
        private int min;
        private int max;

        public ValidateRangeLengthAttribute(int min, int max)
        {
            this.max = max;
            this.min = min;
        }

        public override bool Validate(object value, out string msg)
        {
            if (value != null && value.ToString().Trim().Length >= this.min && value.ToString().Trim().Length <= this.max)
            {
                msg = string.Empty;
                return true;
            }
            else
            {
                msg = $"长度范围为：[{this.min}—{this.max}]";
                return false;
            }
        }
    }
}
